package com.springblog.serviceimpl;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.springblog.common.utils.PageUtils;
import com.springblog.entity.BlogEntity;
import com.springblog.entity.vo.BlogVo;
import com.springblog.mapper.BlogMapper;
import com.springblog.service.BlogService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.PageRequest;
import org.springframework.data.domain.Sort;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Map;

/**
 * <p>
 * 服务实现类
 * </p>
 *
 * @author ifredom@gmail.com
 * @since 2022-04-23
 */
@Service
public class BlogServiceImpl extends ServiceImpl<BlogMapper, BlogEntity> implements BlogService {
    @Autowired
    private BlogMapper blogMapper;

    @Override
    public PageUtils queryPage(Map<String, Object> params) {

        System.out.println(params);
        System.out.println(params.get("page"));

        Integer pageNo = (Integer) params.get("page");
        Integer pageSize = (Integer) params.get("limit");

        Sort sort = Sort.by(Sort.Direction.ASC, "createTime");

        PageRequest pageable = PageRequest.of(pageNo, pageSize);

        List<BlogEntity> list = this.list();

        return new PageUtils(list, list.size(), pageNo, pageSize);
    }

    @Override
    public BlogEntity queryBlogById(long id) {

        return blogMapper.selectBlog(id);
    }

    @Override
    public BlogVo queryBlogVoById(long id) {
        System.out.println("=================id: "+id);
        BlogVo blogVo = blogMapper.selectBlogAuthor(id);
        System.out.println("================="+blogVo);
        return blogVo;
    }
}
